﻿using DevComponents.DotNetBar;
using Elike.Toolkit.ControlsErgodic.Windows;
using shopsoft.main.AppCommon;
using shopsoft.models;
using shopsoft.models.ClassBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace shopsoft.main.MemberManage
{
    public partial class MemberAu : Office2007Form
    {
        private Member memberModel = new Member();

        /// <summary>
        /// 构造函数
        /// </summary>
        public MemberAu()
        {
            InitializeComponent();
            Icon = Properties.Resources.RolePermission16;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_member"></param>
        public MemberAu(Member _member)
        {
            InitializeComponent();
            memberModel = _member;
            Icon = Properties.Resources.RolePermission16;
        }

        /// <summary>
        ///  窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MemberAu_Load(object sender, EventArgs e)
        {
            //绑定优惠方式
            BindOffType();

            //绑定会员等级
            BindMemberGrade();

            //绑定会员状态
            BindMemberStatus();

            //绑定会员性别
            BindMemberSex();

            //绑定会员证件类型
            BindIdentityTypes();

            //绑定信息
            BindMember();
        }

        /// <summary>
        /// 保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (ValidateInput())
            { }
            else
            {
                DialogResult = DialogResult.None;
            }
        }

        /// <summary>
        /// 退出按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            //
            this.Close();
        }

        #region Method

        /// <summary>
        /// 绑定优惠方式
        /// </summary>
        protected void BindOffType()
        {
            List<DataRecord> offTypes = ParameterConfig.GetOffTypes();

            offTypes[0].Name = string.Format("请选择", "");

            ComboBoxErgodic.DataBind(comBoxOffType, offTypes, "ID", "Name");
        }

        /// <summary>
        /// 绑定会员等级
        /// </summary>
        protected void BindMemberGrade()
        {
            List<MemberGrade> memberGrades = ParameterConfig.GetMemberGrades();

            memberGrades[0].Name = string.Format("请选择", "");

            ComboBoxErgodic.DataBind(comBoxMemberGrade, memberGrades, "ID", "Name");
        }

        /// <summary>
        /// 绑定会员状态
        /// </summary>
        protected void BindMemberStatus()
        {
            List<DataRecord> memberStatus = ParameterConfig.GetMemberStatus();

            memberStatus[0].Name = string.Format("请选择", "");

            ComboBoxErgodic.DataBind(comBoxMemberStatus, memberStatus, "ID", "Name");
        }

        /// <summary>
        /// 绑定会员状态
        /// </summary>
        protected void BindMemberSex()
        {
            List<DataRecord> memberSex = ParameterConfig.GetMemberSex();

            memberSex[0].Name = string.Format("请选择", "");

            ComboBoxErgodic.DataBind(comBoxSex, memberSex, "ID", "Name");
        }

        /// <summary>
        /// 绑定会员证件类型
        /// </summary>
        protected void BindIdentityTypes()
        {
            List<DataRecord> memberIdentityTypes = ParameterConfig.GetMemberIdentityTypes();

            memberIdentityTypes[0].Name = string.Format("请选择", "");

            ComboBoxErgodic.DataBind(comBoxIdentityType, memberIdentityTypes, "ID", "Name");
        }

         /// <summary>
        /// 绑定信息
        /// </summary>
        public void BindMember()
        {
            try
            {
                if (memberModel.ID != null)
                {
                }
            }
            catch (Exception ex)
            {
                MsgBox.Information("提示", ex.Message);
            }
        }

        /// <summary>
        /// 验证输入
        /// </summary>
        /// <returns></returns>
        private bool ValidateInput()
        {
            bool flag = false;

            errorProvider1.Clear();

            if (txtMemberCardNO.Text.Trim() == "")
            {
                errorProvider1.SetError(txtMemberCardNO, "请输入[会员卡号]！");
                txtMemberCardNO.Focus();
            }
            else if (txtMemberName.Text.Trim() == "")
            {
                errorProvider1.SetError(txtMemberName, "请输入[会员名称]！");
                txtMemberName.Focus();
            }
            else if (comBoxOffType.SelectedValue == null)
            {
                errorProvider1.SetError(comBoxOffType, "请选择[优惠方式]！");
                comBoxOffType.Focus();
            }
            else if (comBoxMemberGrade.SelectedValue == null)
            {
                errorProvider1.SetError(comBoxMemberGrade, "请选择[会员等级]！");
                comBoxMemberGrade.Focus();
            }
            else if (txtPassword.Text.Trim() == "")
            {
                errorProvider1.SetError(txtPassword, "请输入[会员密码]！");
                txtPassword.Focus();
            }
            else if (txtComfirmPassword.Text.Trim() == "")
            {
                errorProvider1.SetError(txtComfirmPassword, "请输入[确认密码]！");
                txtComfirmPassword.Focus();
            }
            else if (!txtPassword.Text.Trim().Equals(txtComfirmPassword.Text.Trim()))
            {
                errorProvider1.SetError(txtComfirmPassword, "[会员密码]与[确认密码]不一致，请重新输入！");
                txtComfirmPassword.Focus();
            }
            else if (txMemberBouns.Text.Trim() == "")
            {
                errorProvider1.SetError(txMemberBouns, "请输入[会员积分]！");
                txMemberBouns.Focus();
            }
            else if (txtAmountMoney.Text.Trim() == "")
            {
                errorProvider1.SetError(txtAmountMoney, "请输入[储值金额]！");
                txtAmountMoney.Focus();
            }
            else if (comBoxMemberStatus.SelectedValue == null)
            {
                errorProvider1.SetError(comBoxMemberStatus, "请选择[会员状态]！");
                comBoxMemberStatus.Focus();
            }
            else
            {
                flag = true;
            }

            return flag;
        }
        #endregion
    }
}
